﻿using System;
using System.Net.Http;
using System.Web.Http;

namespace Cypher.Sample.WebAPI.Controllers
{
	[RoutePrefix("api/products")]
	public class ProductController : ApiController
	{
		#region Methods

		/// <summary>
		/// Returns a list of available products
		/// </summary>
		/// <returns>System.Net.Http.HttpResponseMessage</returns>
		[HttpGet]
		[Route]
		public System.Net.Http.HttpResponseMessage GetProducts()
		{
			return this.Request.CreateResponse(System.Net.HttpStatusCode.OK, new Cypher.Sample.WebAPI.Repositories.ProductsRepository().GetProducts());
		}

		/// <summary>
		/// Returns a products
		/// </summary>
		/// <returns>System.Net.Http.HttpResponseMessage</returns>
		[HttpGet]
		[Route("{id:int}")]
		public System.Net.Http.HttpResponseMessage GetProduct(int id)
		{
			var repository = new Cypher.Sample.WebAPI.Repositories.ProductsRepository();
			object product = repository.GetProduct(id);
			return this.Request.CreateResponse<object>(System.Net.HttpStatusCode.OK, product);
		}

		#endregion
	}
}
